var xmlhttp;
if(window.XMLHttpRequest){
    //IE7,fireFox,chrome,Opera,sofari
    xmlhttp = new  XMLHttpRequest();
}else{
    xmlhttp = new ActiveXObject("Micosoft.XMLHTTP");
}

var news_conntent = document.getElementById("news_content");

//HTTP是没有状态的，定义
//404(not found) 200(ok) 50x(服务器应用程序错误)
//定义回调函数
xmlhttp.onreadystatechange = function () {
    if(xmlhttp.readyState ===4 && xmlhttp.status === 200){
        //news_conntent.innerText = xmlhttp.responseText;
        //json。parse（）把文本数据解析为json对象
        showJson(JSON.parse(xmlhttp.responseText));
    }
};

//http访问方法： GET POST ....
//xmlhttp.open("GET","http://api.douban.com/v2/movie/top250",true);
xmlhttp.open("GET","data/news.json",true);
xmlhttp.send();


function showJson(jsonData) {
    document.getElementById("title").innerText = jsonData.title;
    var tempHtml = "";
    for (var i=0;i<10;i++){
        //tempHtml += "<li>" + jsonData.subjects[i].title +"</li>>\n";
        tempHtml +="<li>";
        tempHtml += jsonData.subjects[i].title;
        tempHtml += "<img src=\"";
        tempHtml += jsonData.subjects[i].image.medium;
        tempHtml +=jsonData.subjects[i].title;
        tempHtml +="\"";
    }
    document.getElementById("news_list").innerHTML = tempHtml;
}